package me.zhengjie.modules.quartz.service.impl;

import com.google.common.collect.Lists;
import com.qiaofang.applet.service.other.domain.CityCompany;
import com.qiaofang.applet.service.other.service.CityCompanyService;
import com.qiaofang.applet.service.property.service.PropertyRedundancyService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.data.domain.ExampleMatcher;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: youqing.yang
 * @create: 2020/09/28 09:42
 **/
@Slf4j
@Component
public class PropertyRedundancyTaskService {

    @Autowired
    private CityCompanyService cityCompanyService;

    @Autowired
    private PropertyRedundancyService propertyRedundancyService;

    public void updateOtherToProperty() {
        //以公司分类
        try {
            List<CityCompany> allCompanyLists = getAllCompanyLists();
            //所有公司
            allCompanyLists.forEach(company->{
                log.info("updateOtherToProperty companyUuid:{}",company.getCompanyUuid());
                propertyRedundancyService.UpdateOtherToProperty(company);
                propertyRedundancyService.UpdatePropertyToOther(company);
            });
        } catch (Exception e) {
            log.error("updateOtherToProperty error {}:",e);
        }
    }

    /**
     * 获取状态正常的公司
     * @return
     */
    public List<CityCompany> getAllCompanyLists(){
        ExampleMatcher matcher = ExampleMatcher.matching()
                .withMatcher("status", match -> match.exact())
                .withIgnoreNullValues();
        CityCompany cityCompany = new CityCompany();
        cityCompany.setStatus(1);
        Iterable<CityCompany> allCityCompany = cityCompanyService.findAll(Example.of(cityCompany, matcher));
        ArrayList<CityCompany> cityCompanies = Lists.newArrayList(allCityCompany);
        return cityCompanies;
    }


    /**
     * vr
     */
    public void updateVrToProperty(){
        List<CityCompany> allCompanyLists = getAllCompanyLists();
        if (CollectionUtils.isEmpty(allCompanyLists)){
            return;
        }
        allCompanyLists.forEach(company->{
            propertyRedundancyService.redundancyVr(company);
        });
    }

    /**
     * video
     */
    public void updateVedioToProperty(){
        List<CityCompany> allCompanyLists = getAllCompanyLists();
        if (CollectionUtils.isEmpty(allCompanyLists)){
            return;
        }
        allCompanyLists.forEach(company->{
            propertyRedundancyService.redundancyVideo(company);
        });

    }

    /**
     * 楼盘
     */
    public void updateEstateToProperty(){
        List<CityCompany> allCompanyLists = getAllCompanyLists();
        if (CollectionUtils.isEmpty(allCompanyLists)){
            return;
        }
        allCompanyLists.forEach(company->{
            propertyRedundancyService.redundancyEstate(company);
        });

    }

    /**
     * 商圈
     */
    public void updateAreaToProperty(){
        List<CityCompany> allCompanyLists = getAllCompanyLists();
        if (CollectionUtils.isEmpty(allCompanyLists)){
            return;
        }
        allCompanyLists.forEach(company->{
            propertyRedundancyService.redundancyArea(company);
        });

    }

    /**
     * 区域
     */
    public void updateDistrictToProperty(){
        List<CityCompany> allCompanyLists = getAllCompanyLists();
        if (CollectionUtils.isEmpty(allCompanyLists)){
            return;
        }
        allCompanyLists.forEach(company->{
            propertyRedundancyService.redundancyDistrict(company);
        });
    }

    /**
     * 联系人
     */
    public void updateContactToProperty(){
        List<CityCompany> allCompanyLists = getAllCompanyLists();
        if (CollectionUtils.isEmpty(allCompanyLists)){
            return;
        }
        allCompanyLists.forEach(company->{
            propertyRedundancyService.redundancyContact(company);
        });
    }

    /**
     * 经纪人
     */
    public void updateEmployeeToProperty(){
        List<CityCompany> allCompanyLists = getAllCompanyLists();
        if (CollectionUtils.isEmpty(allCompanyLists)){
            return;
        }
        allCompanyLists.forEach(company->{
            propertyRedundancyService.redundancyEmployee(company);
        });

    }

    /**
     * 部门
     */
    public void updateDepartmentToProperty(){
        List<CityCompany> allCompanyLists = getAllCompanyLists();
        if (CollectionUtils.isEmpty(allCompanyLists)){
            return;
        }
        allCompanyLists.forEach(company->{
            propertyRedundancyService.redundancyDepartment(company);
        });
    }




}
